package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //Scanner sc = new Scanner(System.in);
        //System.out.println("请输入一个类名:");
        //String name = sc.nextLine();

        //Class cls1 = Class.forName(name);
        Class cls1 = Class.forName("reflect.Person");

        Constructor constructor2 = cls1.getConstructor();
        Object boj2 = constructor2.newInstance();
        System.out.println(boj2);

        Constructor constructor = cls1.getConstructor(String.class);
        Object obj = constructor.newInstance("李四");
        System.out.println(obj);

        Constructor constructor1 = cls1.getConstructor(String.class,int.class);
        Object obj1 = constructor1.newInstance("王二麻子",22);
        System.out.println(obj1);



    }
}
